package archimede;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Scanner;

import javax.swing.BorderFactory;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;

public class Impermeabilizzazione extends JPanel {

	// scelta della prima colonna come tipo di 'edificio'
	private String[] elTipo1 = { "",
			"<html>marciapiede isolamento<br>verticale attacco muro</html>",
			"<html>terrazzo isolamento<br>verticale attacco muro</html>" };
	private String[] elTipo2 = { "",
			"<html>marciapiede isolamento<br>verticale di testa</html>",
			"<html>terrazzo isolamento<br>verticale di testa</html>" };
	private String[] elTipo3 = { "",
			"<html>marciapiede isolamento<br>orizzontale</html>",
			"<html>terrazzo isolamento<br>orizzontale</html>" };
	private JComboBox tipo1 = new JComboBox(elTipo1);
	private JComboBox tipo2 = new JComboBox(elTipo2);
	private JComboBox tipo3 = new JComboBox(elTipo3);

	/**
	 * elements of isolamento
	 */
	private String[] elIsolamento = { "", "si", "no", "non rilevabile",
			"forse", "altro" };
	/**
	 * elements of materiali vetticali
	 */
	private String[] elMaterialiV = { "", "guaina bituminosa",
			"<html>guaina bituminosa<br>\te proteggi guaina</html>",
			"guaina liquida",
			"<html>guaina liquida<br>\te proteggi guaina</html>",
			"carta catramata", "resine", "catramina", "cemento osmotico",
			"altro" };
	/**
	 * elements of materiali vetticali
	 */
	private String[] elMaterialiO = { "", "guaina taglia muro",
			"<html>vetro resina<br> taglia muro</html>", "carta catramata",
			"resina", "altro" };
	/**
	 * elements of metodi verticali
	 */
	private String[] elMetodiV = {
			"",
			"senza drenaggio",
			"drenaggio con ghiaione",
			"<html>drenaggio con ghiaione e<br>   tubo corrugato di scolo</html>",
			"altro" };
	/**
	 * elements of metodi orizzontali
	 */
	private String[] elMetodiO = { "",
			"<html>taglia muro durante<br>   la costruzione</html>",
			"<html>taglia muro durante<br>   la ristrutturazione</html>",
			"barriera chimica", "altro" };
	
	/**
	 * elements of terrazzo materiali
	 */
	private String[] terrazzoMat = { "", "guaina bituminosa", "guaina liquida",
	"carta catramata", "cemento osmotico", "catramina", "altro" };
	
	/**
	 * elements of isolamento
	 */
	private String[] elIso = { "", "water stop", "no", "forse", "altro" };
	
	private JComboBox a1 = new JComboBox(elIsolamento);
	private JComboBox b1 = new JComboBox(elMaterialiV);
	private JComboBox c1 = new JComboBox(elMetodiV);

	private JComboBox a2 = new JComboBox(elIsolamento);
	private JComboBox b2 = new JComboBox(elMaterialiO);
	private JComboBox c2 = new JComboBox(elMetodiO);

	private JComboBox a3 = new JComboBox(elIsolamento);
	private JComboBox b3 = new JComboBox(terrazzoMat);

	private JComboBox a4 = new JComboBox(elIsolamento);
	private JComboBox b4 = new JComboBox(terrazzoMat);

	private JComboBox a5 = new JComboBox(elIsolamento);
	private JComboBox b5 = new JComboBox(terrazzoMat);

	private JComboBox isol = new JComboBox(elIso);

	/**
	 * if i want write something else
	 */
	private JTextField emptyA1 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyB1 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyC1 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyA2 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyB2 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyC2 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyA3 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyB3 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyC3 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyA4 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyB4 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyC4 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyA5 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyB5 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField emptyC5 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};

	private JTextField periodo1 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField periodo2 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField periodo3 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField periodo4 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField periodo5 = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField isolAltro = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};

	/**
	 * se ho fatto le modifiche
	 */
	private boolean modA1 = false;
	private boolean modB1 = false;
	private boolean modC1 = false;
	private boolean modA2 = false;
	private boolean modB2 = false;
	private boolean modC2 = false;
	private boolean modA3 = false;
	private boolean modB3 = false;
	private boolean modA4 = false;
	private boolean modB4 = false;
	private boolean modA5 = false;
	private boolean modB5 = false;
	private boolean modIsol = false;

	private StartingWindow st;

	public Impermeabilizzazione(StartingWindow st) {
		super();
		setOpaque(false);
		this.st = st;

		RoundedPanel tipo = new RoundedPanel("TIPO");
		setCell(tipo);
		tipo.setPreferredSize(new Dimension(210, 35));
		RoundedPanel isolamento = new RoundedPanel("ISOLAMENTO");
		setCell(isolamento);
		isolamento.setPreferredSize(new Dimension(210, 35));
		RoundedPanel elMateriali = new RoundedPanel("MATERIALI USATI");
		setCell(elMateriali);
		elMateriali.setPreferredSize(new Dimension(210, 35));
		RoundedPanel elMetodi = new RoundedPanel("METODI");
		setCell(elMetodi);
		elMetodi.setPreferredSize(new Dimension(210, 35));
		RoundedPanel controTerra = new RoundedPanel(
				"<html>Muro contro terra<br>isolamento verticale</html>");
		setCell(controTerra);
		RoundedPanel pianoTerra = new RoundedPanel(
				"<html>Muro piano terra<br>isolamento orizzontale</html>");
		setCell(pianoTerra);
		RoundedPanel periodo = new RoundedPanel("PERIODO");
		setCell(periodo);
		periodo.setPreferredSize(new Dimension(120, 35));
		RoundedPanel isolamentoFondamenta = new RoundedPanel(
				"<html>Isolamento tra fondamenta e muro contro terra</html>");
		isolamentoFondamenta.setPreferredSize(new Dimension(420, 30));
		isolamentoFondamenta.setOpaque(false);

		setCell();
		addAction();
		addMouse();

		setLayout(new MigLayout("", "[]1[]1[]", "[]5[] 7[] 7[] 7[]7[]7[]"));
		add(tipo, "cell 0 0");
		add(isolamento, "cell 1 0");
		add(elMateriali, "cell 2 0");
		add(elMetodi, "cell 3 0");
		add(periodo, "cell 4 0");
		add(controTerra, "cell 0 1");
		add(a1, "cell 1 1");
		add(b1, "cell 2 1");
		add(c1, "cell 3 1");
		add(periodo1, "cell 4 1");
		add(pianoTerra, "cell 0 2");
		add(a2, "cell 1 2");
		add(b2, "cell 2 2");
		add(c2, "cell 3 2");
		add(periodo2, "cell 4 2");
		add(tipo1, "cell 0 3");
		add(a3, "cell 1 3");
		add(b3, "cell 2 3");
		add(emptyC3, "cell 3 3");
		add(periodo3, "cell 4 3");
		add(tipo2, "cell 0 4");
		add(a4, "cell 1 4");
		add(b4, "cell 2 4");
		add(emptyC4, "cell 3 4");
		add(periodo4, "cell 4 4");
		add(tipo3, "cell 0 5");
		add(a5, "cell 1 5");
		add(b5, "cell 2 5");
		add(emptyC5, "cell 3 5");
		add(periodo5, "cell 4 5");
		add(isolamentoFondamenta, "cell 0 6 2 1");
		add(isol, "cell 2 6");

	}

	public void setCell(JComponent c) {
		c.setPreferredSize(new Dimension(210, 45));
		c.setOpaque(false);
	
	}

	public void setCell() {
		emptyA1.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyB1.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyC1.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyA2.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyB2.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyC2.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyA3.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyB3.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyC3.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyA4.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyB4.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyC4.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyA5.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyB5.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		emptyC5.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		periodo1.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		periodo2.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		periodo3.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		periodo4.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		periodo5.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		isolAltro.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));

		tipo1.setFont(new Font("Arial", Font.PLAIN, 14));
		tipo2.setFont(new Font("Arial", Font.PLAIN, 14));
		tipo3.setFont(new Font("Arial", Font.PLAIN, 14));
		a1.setFont(new Font("Arial", Font.PLAIN, 14));
		b1.setFont(new Font("Arial", Font.PLAIN, 14));
		c1.setFont(new Font("Arial", Font.PLAIN, 14));
		a2.setFont(new Font("Arial", Font.PLAIN, 14));
		b2.setFont(new Font("Arial", Font.PLAIN, 14));
		c2.setFont(new Font("Arial", Font.PLAIN, 14));
		a3.setFont(new Font("Arial", Font.PLAIN, 14));
		b3.setFont(new Font("Arial", Font.PLAIN, 14));
		a4.setFont(new Font("Arial", Font.PLAIN, 14));
		b4.setFont(new Font("Arial", Font.PLAIN, 14));
		a5.setFont(new Font("Arial", Font.PLAIN, 14));
		b5.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyA1.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyB1.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyC1.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyA2.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyB2.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyC2.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyA3.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyB3.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyC3.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyA4.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyB4.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyC4.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyA5.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyB5.setFont(new Font("Arial", Font.PLAIN, 14));
		emptyC5.setFont(new Font("Arial", Font.PLAIN, 14));
		periodo1.setFont(new Font("Arial", Font.PLAIN, 14));
		periodo2.setFont(new Font("Arial", Font.PLAIN, 14));
		periodo3.setFont(new Font("Arial", Font.PLAIN, 14));
		periodo4.setFont(new Font("Arial", Font.PLAIN, 14));
		periodo5.setFont(new Font("Arial", Font.PLAIN, 14));
		isolAltro.setFont(new Font("Arial", Font.PLAIN, 14));

		tipo1.setPreferredSize(new Dimension(210, 45));
		tipo2.setPreferredSize(new Dimension(210, 45));
		tipo3.setPreferredSize(new Dimension(210, 45));
		a1.setPreferredSize(new Dimension(210, 45));
		b1.setPreferredSize(new Dimension(210, 45));
		c1.setPreferredSize(new Dimension(210, 45));
		a2.setPreferredSize(new Dimension(210, 45));
		b2.setPreferredSize(new Dimension(210, 45));
		c2.setPreferredSize(new Dimension(210, 45));
		a3.setPreferredSize(new Dimension(210, 45));
		b3.setPreferredSize(new Dimension(210, 45));
		a4.setPreferredSize(new Dimension(210, 45));
		b4.setPreferredSize(new Dimension(210, 45));
		a5.setPreferredSize(new Dimension(210, 45));
		b5.setPreferredSize(new Dimension(210, 45));
		emptyA1.setPreferredSize(new Dimension(210, 45));
		emptyB1.setPreferredSize(new Dimension(210, 45));
		emptyC1.setPreferredSize(new Dimension(210, 45));
		emptyA2.setPreferredSize(new Dimension(210, 45));
		emptyB2.setPreferredSize(new Dimension(210, 45));
		emptyC2.setPreferredSize(new Dimension(210, 45));
		emptyA3.setPreferredSize(new Dimension(210, 45));
		emptyB3.setPreferredSize(new Dimension(210, 45));
		emptyC3.setPreferredSize(new Dimension(210, 45));
		emptyA4.setPreferredSize(new Dimension(210, 45));
		emptyB4.setPreferredSize(new Dimension(210, 45));
		emptyC4.setPreferredSize(new Dimension(210, 45));
		emptyA5.setPreferredSize(new Dimension(210, 45));
		emptyB5.setPreferredSize(new Dimension(210, 45));
		emptyC5.setPreferredSize(new Dimension(210, 45));
		periodo1.setPreferredSize(new Dimension(120, 45));
		periodo2.setPreferredSize(new Dimension(120, 45));
		periodo3.setPreferredSize(new Dimension(120, 45));
		periodo4.setPreferredSize(new Dimension(120, 45));
		periodo5.setPreferredSize(new Dimension(120, 45));
		isol.setPreferredSize(new Dimension(210, 30));
		isolAltro.setPreferredSize(new Dimension(210, 30));

		tipo1.setBackground(new Color(189, 200, 200));
		tipo2.setBackground(new Color(189, 200, 200));
		tipo3.setBackground(new Color(189, 200, 200));
		
		
		tipo1.setOpaque(true);
		tipo2.setOpaque(true);
		tipo3.setOpaque(true);
		emptyA1.setOpaque(false);
		emptyB1.setOpaque(false);
		emptyC1.setOpaque(false);
		emptyA2.setOpaque(false);
		emptyB2.setOpaque(false);
		emptyC2.setOpaque(false);
		emptyA3.setOpaque(false);
		emptyB3.setOpaque(false);
		emptyC3.setOpaque(false);
		emptyA4.setOpaque(false);
		emptyB4.setOpaque(false);
		emptyC4.setOpaque(false);
		emptyA5.setOpaque(false);
		emptyB5.setOpaque(false);
		emptyC5.setOpaque(false);
		periodo1.setOpaque(false);
		periodo2.setOpaque(false);
		periodo3.setOpaque(false);
		periodo4.setOpaque(false);
		periodo5.setOpaque(false);
		isolAltro.setOpaque(false);
	}

	/**
	 * click destro del mouse torno alla vista del menu a tendina
	 */
	public void addMouse() {
		
		MouseAdapter mlA1 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyA1);
					a1.setSelectedIndex(0);
					add(a1, "cell 1 1");
					modA1 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyA1.addMouseListener(mlA1);
		MouseAdapter mlB1 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyB1);
					b1.setSelectedIndex(0);
					add(b1, "cell 2 1");
					modB1 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyB1.addMouseListener(mlB1);
		MouseAdapter mlC1 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyC1);
					c1.setSelectedIndex(0);
					add(c1, "cell 3 1");
					modC1 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyC1.addMouseListener(mlC1);
		MouseAdapter mlA2 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyA2);
					a2.setSelectedIndex(0);
					add(a2, "cell 1 2");
					modA2 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyA2.addMouseListener(mlA2);
		MouseAdapter mlB2 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyB2);
					b2.setSelectedIndex(0);
					add(b2, "cell 2 2");
					modB2 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyB2.addMouseListener(mlB2);
		MouseAdapter mlC2 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyC2);
					c2.setSelectedIndex(0);
					add(c2, "cell 3 2");
					modC2 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyC2.addMouseListener(mlC2);
		MouseAdapter mlA3 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyA3);
					a3.setSelectedIndex(0);
					add(a3, "cell 1 3");
					modA3 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyA3.addMouseListener(mlA3);
		MouseAdapter mlB3 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyB3);
					b3.setSelectedIndex(0);
					add(b3, "cell 2 3");
					modB3 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyB3.addMouseListener(mlB3);

		MouseAdapter mlA4 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyA4);
					a4.setSelectedIndex(0);
					add(a4, "cell 1 4");
					modA4 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyA4.addMouseListener(mlA4);
		MouseAdapter mlB4 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyB4);
					b4.setSelectedIndex(0);
					add(b4, "cell 2 4");
					modB4 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyB4.addMouseListener(mlB4);

		MouseAdapter mlA5 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyA5);
					a5.setSelectedIndex(0);
					add(a5, "cell 1 5");
					modA5 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyA5.addMouseListener(mlA5);
		MouseAdapter mlB5 = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(emptyB5);
					b5.setSelectedIndex(0);
					add(b5, "cell 2 5");
					modB5 = false;

					paintAll(getGraphics());
				}
			}
		};
		emptyB5.addMouseListener(mlB5);

		MouseAdapter mlIsol = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					remove(isolAltro);
					isol.setSelectedIndex(0);
					add(isol, "cell 2 6");
					modIsol = false;

					paintAll(getGraphics());
				}
			}
		};
		isolAltro.addMouseListener(mlIsol);

	}

	/**
	 * quando seleziono altro compare il campo testo libero
	 */
	public void addAction() {

		a1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) a1.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(a1);
					add(emptyA1, "cell 1 1");
					modA1 = true;
					paintAll(getGraphics());
				}
			}
		});
		a2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) a2.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(a2);
					add(emptyA2, "cell 1 2");
					modA2 = true;
					paintAll(getGraphics());
				}
			}
		});
		a3.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) a3.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(a3);
					add(emptyA3, "cell 1 3");
					modA3 = true;
					paintAll(getGraphics());
				}
			}
		});
		a4.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) a4.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(a4);
					add(emptyA4, "cell 1 4");
					modA4 = true;
					paintAll(getGraphics());
				}
			}
		});
		a5.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) a5.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(a5);
					add(emptyA5, "cell 1 5");
					modA5 = true;
					paintAll(getGraphics());
				}
			}
		});
		b1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) b1.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(b1);
					add(emptyB1, "cell 2 1");
					modB1 = true;
					paintAll(getGraphics());
				}
			}
		});
		b2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) b2.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(b2);
					add(emptyB2, "cell 2 2");
					modB2 = true;
					paintAll(getGraphics());
				}
			}
		});
		b3.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) b3.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(b3);
					add(emptyB3, "cell 2 3");
					modB3 = true;
					paintAll(getGraphics());
				}
			}
		});
		b4.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) b4.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(b4);
					add(emptyB4, "cell 2 4");
					modB4 = true;
					paintAll(getGraphics());
				}
			}
		});
		b5.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) b5.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(b5);
					add(emptyB5, "cell 2 5");
					modB5 = true;
					paintAll(getGraphics());
				}
			}
		});
		c1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) c1.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(c1);
					add(emptyC1, "cell 3 1");
					modC1 = true;
					paintAll(getGraphics());
				}
			}
		});
		c2.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) c2.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(c2);
					add(emptyC2, "cell 3 2");
					modC2 = true;
					paintAll(getGraphics());
				}
			}
		});
		isol.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {

				if (((String) isol.getSelectedItem()).equalsIgnoreCase("altro")) {
					remove(isol);
					add(isolAltro, "cell 2 6");
					modIsol = true;
					paintAll(getGraphics());
				}
			}
		});

	}

	public String print() {
		String print = "\n#";
		if (modA1)
			print = print + emptyA1.getText() + "\n#";
		else
			print = print + a1.getSelectedIndex() + "\n#";
		if (modB1)
			print = print + emptyB1.getText() + "\n#";
		else
			print = print + b1.getSelectedIndex() + "\n#";
		if (modC1)
			print = print + emptyC1.getText() + "\n#";
		else
			print = print + c1.getSelectedIndex() + "\n#";
		print = print + periodo1.getText() + "\n#";

		if (modA2)
			print = print + emptyA2.getText() + "\n#";
		else
			print = print + a2.getSelectedIndex() + "\n#";
		if (modB2)
			print = print + emptyB2.getText() + "\n#";
		else
			print = print + b2.getSelectedIndex() + "\n#";
		if (modC2)
			print = print + emptyC2.getText() + "\n#";
		else
			print = print + c2.getSelectedIndex() + "\n#";
		print = print + periodo2.getText() + "\n#";

		print = print + tipo1.getSelectedIndex() + "\n#";
		if (modA3)
			print = print + emptyA3.getText() + "\n#";
		else
			print = print + a3.getSelectedIndex() + "\n#";
		if (modB3)
			print = print + emptyB3.getText() + "\n#";
		else
			print = print + b3.getSelectedIndex() + "\n#";

		print = print + emptyC3.getText() + "\n#";
		print = print + periodo3.getText() + "\n#";

		print = print + tipo2.getSelectedIndex() + "\n#";
		if (modA4)
			print = print + emptyA4.getText() + "\n#";
		else
			print = print + a4.getSelectedIndex() + "\n#";
		if (modB4)
			print = print + emptyB4.getText() + "\n#";
		else
			print = print + b4.getSelectedIndex() + "\n#";

		print = print + emptyC4.getText() + "\n#";
		print = print + periodo4.getText() + "\n#";

		print = print + tipo3.getSelectedIndex() + "\n#";
		if (modA5)
			print = print + emptyA5.getText() + "\n#";
		else
			print = print + a5.getSelectedIndex() + "\n#";
		if (modB5)
			print = print + emptyB5.getText() + "\n#";
		else
			print = print + b5.getSelectedIndex() + "\n#";

		print = print + emptyC5.getText() + "\n#";
		print = print + periodo5.getText() + "\n#";

		if (modIsol)
			print = print + isolAltro.getText();
		else
			print = print + isol.getSelectedIndex();

		return print;
	}

	public void setElement(String data) {
		Scanner c = new Scanner(data);
		c.nextLine();
		String tmp = c.nextLine();
		try {
			a1.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyA1.setText(tmp);
			remove(a1);
			add(emptyA1, "cell 1 1");
			modA1 = true;

		}
		tmp = c.nextLine();
		try {
			b1.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyB1.setText(tmp);
			remove(b1);
			add(emptyB1, "cell 2 1");
			modB1 = true;
		}
		tmp = c.nextLine();
		try {
			c1.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyC1.setText(tmp);
			remove(c1);
			add(emptyC1, "cell 3 1");
			modC1 = true;
			paintAll(getGraphics());
		}
		tmp = c.nextLine();
		periodo1.setText(tmp);

		tmp = c.nextLine();
		try {
			a2.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyA2.setText(tmp);
			remove(a2);
			add(emptyA2, "cell 1 2");
			modA2 = true;
		}
		tmp = c.nextLine();
		try {
			b2.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyB2.setText(tmp);
			remove(b2);
			add(emptyB2, "cell 2 2");
			modB2 = true;
		}
		tmp = c.nextLine();
		try {
			c2.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyC2.setText(tmp);
			remove(c2);
			add(emptyC2, "cell 3 2");
			modC2 = true;
		}
		tmp = c.nextLine();
		periodo2.setText(tmp);

		tmp = c.nextLine();
		tipo1.setSelectedIndex(Integer.parseInt(tmp));

		tmp = c.nextLine();
		try {
			a3.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyA3.setText(tmp);
			remove(a3);
			add(emptyA3, "cell 1 3");
			modA3 = true;
		}
		tmp = c.nextLine();
		try {
			b3.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyB3.setText(tmp);
			remove(b3);
			add(emptyB3, "cell 2 3");
			modB3 = true;
		}
		tmp = c.nextLine();

		emptyC3.setText(tmp);
		tmp = c.nextLine();
		periodo3.setText(tmp);

		tmp = c.nextLine();
		tipo2.setSelectedIndex(Integer.parseInt(tmp));

		tmp = c.nextLine();
		try {
			a4.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyA4.setText(tmp);
			remove(a4);
			add(emptyA4, "cell 1 4");
			modA4 = true;
		}
		tmp = c.nextLine();
		try {
			b4.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyB4.setText(tmp);
			remove(b4);
			add(emptyB4, "cell 2 4");
			modB4 = true;
		}
		tmp = c.nextLine();

		emptyC4.setText(tmp);
		tmp = c.nextLine();
		periodo4.setText(tmp);

		tmp = c.nextLine();
		tipo3.setSelectedIndex(Integer.parseInt(tmp));

		tmp = c.nextLine();
		try {
			a5.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyA5.setText(tmp);
			remove(a5);
			add(emptyA5, "cell 1 5");
			modA5 = true;
		}
		tmp = c.nextLine();
		try {
			b5.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			emptyB5.setText(tmp);
			remove(b5);
			add(emptyB5, "cell 2 5");
			modB5 = true;
		}
		tmp = c.nextLine();

		emptyC5.setText(tmp);
		tmp = c.nextLine();
		periodo5.setText(tmp);

		tmp = c.nextLine();
		try {
			isol.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			isolAltro.setText(tmp);
			remove(isol);
			add(isolAltro, "cell 2 5");
			modIsol = true;
		}

		st.refresh();
	}

	public Document PDF(Document doc) {
		Paragraph dati;
		dati = new Paragraph("3.2 Impermeabilizzazione", FontFactory.getFont(
				FontFactory.TIMES, 13, Font.BOLD));
		try {
			dati.setSpacingAfter(10);
			dati.setSpacingBefore(40);
			doc.add(dati);
		} catch (DocumentException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		PdfPTable table = new PdfPTable(5);
		int[] size = { 60, 60, 60, 60, 30 };
		try {
			table.setWidths(size);
			table.setWidthPercentage(100);
		} catch (DocumentException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Phrase testo = new Phrase("Tipo", FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		PdfPCell cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase("Presenza isolamento", FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase("Materiali usati", FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase("Metodi usati", FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase("Periodo", FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		// line1
		testo = new Phrase("Muro contro terra isolamento verticale",
				FontFactory.getFont(FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modA1)
			testo = new Phrase(emptyA1.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) a1.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modB1)
			testo = new Phrase(emptyB1.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) b1.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modC1)
			testo = new Phrase(emptyC1.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) c1.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(periodo1.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		// line2
		testo = new Phrase("Muro piano terra isolamento orizzontale",
				FontFactory.getFont(FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modA2)
			testo = new Phrase(emptyA2.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) a2.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modB2)
			testo = new Phrase(emptyB2.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) b2.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modC2)
			testo = new Phrase(emptyC2.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) c2.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(periodo2.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		// line3

		testo = new Phrase(((String) tipo1.getSelectedItem())
				.replace("<html>", "").replace("<br>", " ")
				.replace("</html>", ""), FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modA3)
			testo = new Phrase(emptyA3.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) a3.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modB3)
			testo = new Phrase(emptyB3.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) b3.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(emptyC3.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));

		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(periodo3.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		// line4

		testo = new Phrase(((String) tipo2.getSelectedItem())
				.replace("<html>", "").replace("<br>", " ")
				.replace("</html>", ""), FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modA4)
			testo = new Phrase(emptyA4.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) a4.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modB4)
			testo = new Phrase(emptyB4.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) b4.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(emptyC4.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));

		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(periodo4.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		// line5

		testo = new Phrase(((String) tipo3.getSelectedItem())
				.replace("<html>", "").replace("<br>", " ")
				.replace("</html>", ""), FontFactory.getFont(
				FontFactory.TIMES, 11, Font.BOLD));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modA5)
			testo = new Phrase(emptyA5.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) a5.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		if (modB5)
			testo = new Phrase(emptyB5.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) b5.getSelectedItem())
					.replace("<html>", "").replace("<br>", " ")
					.replace("</html>", ""), FontFactory.getFont(
					FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(emptyC5.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));

		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase(periodo5.getText(), FontFactory.getFont(
				FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(30);
		table.addCell(cos);

		testo = new Phrase("Isolamento tra fondamenta e muro contro terra",
				FontFactory.getFont(FontFactory.TIMES, 11, Font.BOLD));

		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_CENTER);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(22);
		cos.setColspan(2);
		table.addCell(cos);

		if (modIsol)
			testo = new Phrase(isolAltro.getText(), FontFactory.getFont(
					FontFactory.TIMES, 11));
		else
			testo = new Phrase(((String) isol.getSelectedItem()),
					FontFactory.getFont(FontFactory.TIMES, 11));
		cos = new PdfPCell(testo);
		cos.setHorizontalAlignment(Element.ALIGN_LEFT);
		cos.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cos.setFixedHeight(22);
		cos.setColspan(3);
		table.addCell(cos);

		try {

			doc.add(table);
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doc;
	}
}
